<?php
declare (strict_types = 1);

namespace app\command\backend\system;

use app\model\communal\AdminModel;
use Carbon\Carbon;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use think\console\Command;

/**
 * 员工设置/取消超管
 *
 * Class RoleInit
 * @package app\command\backend\system
 */
class AdminSuper extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('super admin set/cancel')
            ->addArgument('mobile', Argument::REQUIRED, "员工手机号,逗号分割")
            ->addArgument('is_super', Argument::REQUIRED, "是否超管 1是 2否")
            ->setDescription('the super admin set/cancel command');
    }

    protected function execute(Input $input, Output $output)
    {
        $output->writeln('超管员工设置/取消开始');
        $mobiles = $input->getArgument('mobile');
        $isSuper = $input->getArgument('is_super');

        if (!empty($mobiles) && in_array($isSuper, [1,2])) {
            $mobiles = explode(',', $mobiles);
            AdminModel::whereIn('mobile', $mobiles)->update(['is_super' => $isSuper]);
        }

        // 指令输出
        $output->writeln('超管员工设置/取消结束-' . Carbon::now()->format('Y-m-d H:i:s'));
    }
}
